/**
 * Mock 数据配置
 * 在开发环境中模拟后端 API 接口数据
 */

// 模拟延迟时间 (ms)
const MOCK_DELAY = {
  MIN: 300,
  MAX: 800
}

/**
 * 随机延迟函数
 */
const randomDelay = (): Promise<void> => {
  const delay = Math.floor(Math.random() * (MOCK_DELAY.MAX - MOCK_DELAY.MIN + 1)) + MOCK_DELAY.MIN
  return new Promise(resolve => setTimeout(resolve, delay))
}

/**
 * 生成随机 ID
 */
const generateId = (prefix: string = ''): string => {
  const timestamp = Date.now()
  const random = Math.floor(Math.random() * 10000)
  return `${prefix}${timestamp}${random}`
}

/**
 * 生成随机手机号
 */
const generatePhone = (): string => {
  const prefixes = ['138', '139', '150', '151', '152', '158', '159', '188', '189']
  const prefix = prefixes[Math.floor(Math.random() * prefixes.length)]
  const suffix = Math.floor(Math.random() * 100000000).toString().padStart(8, '0')
  return prefix + suffix
}

/**
 * 生成随机邮箱
 */
const generateEmail = (username: string): string => {
  const domains = ['qq.com', '163.com', 'gmail.com', '126.com', 'sina.com']
  const domain = domains[Math.floor(Math.random() * domains.length)]
  return `${username}@${domain}`
}

/**
 * 格式化日期
 */
const formatDate = (date: Date): string => {
  return date.toISOString()
}

/**
 * 生成随机日期（过去30天内）
 */
const generateRandomDate = (days: number = 30): string => {
  const now = new Date()
  const randomDays = Math.floor(Math.random() * days)
  const randomDate = new Date(now.getTime() - randomDays * 24 * 60 * 60 * 1000)
  return formatDate(randomDate)
}

export {
  randomDelay,
  generateId,
  generatePhone,
  generateEmail,
  formatDate,
  generateRandomDate,
  MOCK_DELAY
}